package com.qf.controller;

import com.qf.pojo.Admin;
import com.qf.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("toLogin")
    public String toLogin() {
        return "behind/login.jsp";
    }

    @RequestMapping("login")
    @ResponseBody
    public String login(Admin data, HttpSession session) {

        List<Admin> admin = adminService.findByAdmin(data);
        if (admin != null) {
            session.setAttribute("userName", data.getUsername());
            return "success";

        }
        return null;
    }

    @RequestMapping("exit")
    public String loginOut(HttpSession session) {
        //销毁Session
        session.invalidate();

        return "redirect:toLogin";
    }

}
